<?php /* Smarty version 2.6.20, created on 2012-07-10 12:51:42
         compiled from _core/pagecommon/_mvc/_control/handlepagereceipt.tpl */ ?>
<?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier', 'escape', '_core/pagecommon/_mvc/_control/handlepagereceipt.tpl', 113, false),)), $this); ?>
﻿function HandlePageReceipt(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;
  
  this._customerId = (options && options.id) ? options.id : null;
  this._orderTrackId = (options && options.track) ? options.track : [];
  
  this._createElements();
};

HandlePageReceipt.prototype._createElements = function() {
  this._loadData();
};

HandlePageReceipt.prototype._loadData = function() {
  this._customer = null;
  this._refunds = null;
  this._retrieveCustomer();
  this._retrieveRefunds();
};

HandlePageReceipt.prototype._verifyData = function() {
  if (this._customer && this._retrieveRefunds) {
    this._updateElements();
  }
};

HandlePageReceipt.prototype._retrieveCustomer = function() {
  var _self = this;
  if (this._customerId) {
    /*new RequestUtils()._read('customer', null, 'd.oid =' + this._customerId, null, null, null, null, function(result, params) { _self._customer = (result.data.length == 1) ? result.data[0] : null;
                                                                                                                                _self._verifyData.call(_self);
                                                                                                                              }, null);
 */

   var args = '&oid=' + this._customerId; 
  new RequestUtils()._mysql('v2customer', args, function(result, params) { _self._customer = (result.data.length == 1) ? result.data[0] : null;
                                                                          _self._verifyData.call(_self);
                                                                        }, {php:'customphp/mysqlread.php'});     
 } else {
    this._customer = v1customer.instance();
    this._customer.createdDate = this._now;
    this._customer.sales = this._operator;
    this._verifyData();
  }
};

HandlePageReceipt.prototype._retrieveRefunds = function() {
	  var _self = this;
	  if (this._customerId) {
	  var args = '&oid=' + this._customerId; 
	  new RequestUtils()._mysql('expense', args, function(result, params) { _self._refunds = result.data;
	                                                                          _self._verifyData.call(_self);
	                                                                        }, {php:'customphp/mysqlread.php'});   
	  } else {
	    this._refunds = [];
	    this._verifyData();
	  }
	};


HandlePageReceipt.prototype._updateElements = function() {
  var _self = this, span;
  DlmanageUtils.clear(this._gui);
  
  this._gui.customerNo.appendChild(document.createTextNode(DlmanageUtils.customerId(this._customerId)));
  this._gui.brideName.appendChild(document.createTextNode(this._customer.bridename));
  this._gui.brideLn1.appendChild(document.createTextNode(this._customer.brideaddrLn1));
  this._gui.brideLn2.appendChild(document.createTextNode(this._customer.brideaddrLn2));
  this._gui.bridePhone.appendChild(document.createTextNode(this._customer.bridephone));
  this._gui.brideMobile.appendChild(document.createTextNode(this._customer.bridemobile));
  this._gui.brideEmail.appendChild(document.createTextNode(this._customer.brideemail));
  this._gui.groomName.appendChild(document.createTextNode(this._customer.groomname));
  this._gui.groomLn1.appendChild(document.createTextNode(this._customer.groomaddrLn1));
  this._gui.groomLn2.appendChild(document.createTextNode(this._customer.groomaddrLn2));
  this._gui.groomPhone.appendChild(document.createTextNode(this._customer.groomphone));
  this._gui.groomMobile.appendChild(document.createTextNode(this._customer.groommobile));
  this._gui.groomEmail.appendChild(document.createTextNode(this._customer.groomemail));
  
  /* 显示所有订单的总价和打折率 */
  var total = 0;
  var original = 0;
  var received = 0;
  for (var i = 0, il = this._customer.orders.length; i < il; i++) {
    var order = this._customer.orders[i];
    if (order.disposalstatus == 0) {
      total += parseFloat(order.price, 10);
      original += DlmanageUtils.total(order);
    }
    for (var j = 0, jl = order.payments.length; j < jl; j++) {
      var payment = order.payments[j];
      if (payment.cancelled == 1) {
        continue;
      }
      received += parseFloat(payment.amount);
    }
  }
  
  var rtotal = 0;
  
  for (var i = 0, il = this._refunds.length; i < il; i++) {
    var r = this._refunds[i];
    
    if (r.status != -1) {
      rtotal += parseFloat(r.amount, 10);
    }
  }
  
    received = received - rtotal;
  
  this._gui.price.appendChild(document.createTextNode('$' + (total * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10)).toFixed(2) + ' (Inc. ' +  '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')'));
  
  this._gui.received.appendChild(document.createTextNode('$' + received.toFixed(2)));
  this._gui.anticipated.appendChild(document.createTextNode('$' + ((total * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10)) - received).toFixed(2)));
  
  this._customer._refund = this._refunds;
  
  new IContainerReceipt(this._gui.orderList, this._customer, this._options);
  
};